const multer = require('multer');

//配置storage，处理图片文件的储存位置和文件名称
var storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, './public/userImg')
  },
  filename: function (req, file, cb) {
    //获得originalname以及图片后缀
    const {originalname} = file;
    const suffix = originalname.substring(originalname.lastIndexOf(".")+1)
    //文件名称加上时间戳以及图片后缀
    cb(null, file.fieldname + '-' + Date.now() + "." + suffix);
  }
});

module.exports = multer({ storage: storage });